using UnityEngine;
using System.Collections;

public class BallMove : MonoBehaviour {
	public static bool objectDestroyed = false;
	public int moveSpeed = 70;
	public int numFails = 3;
	public guiScore other;
	Vector3 ballDirection = Vector3.right;
	public Rigidbody ball;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		ballMove();
		if(numFails == 0) {
			Application.LoadLevel("Test");
		}
	}
	
	void ballMove() {
		Vector3 newPosition = Vector3.zero;
		newPosition =  Vector3.left * Time.deltaTime * moveSpeed;
		transform.Translate(newPosition, Space.World);
		if(newPosition.x < -175) {
			numFails--;
			Rigidbody clone;
			clone = Instantiate(ball, transform.position, transform.rotation) as Rigidbody;
			clone.velocity = transform.TransformDirection(Vector3.left * 10);        
			Destroy(gameObject, 1);
		}
	}
	
	void OnCollisionEnter(Collision collision) {
   		

		Rigidbody clone;
		clone = Instantiate(ball, transform.position, transform.rotation) as Rigidbody;
		clone.velocity = transform.TransformDirection(Vector3.left * 10);  
		objectDestroyed = true;
		Destroy(gameObject);
	}
}